package com.phoenix.jsef.framework;

import com.phoenix.jsef.framework.accessfilter.AccessFilter;

/**
 * @version V1.0
 * @ClassName: AccessParameter
 * @Description:TODO(封装查询参数类)
 * @author: 李启联
 * @date: 2018/10/18 16:11
 * @Copyright: Copyright (c), 2018-2018
 * 申明：本内容未经作者本人同意,禁止外泄以及用于其他的商业项目.
 */
public class AccessParameter {

    //// 排序和过滤类
    protected  AccessFilter filter = new AccessFilter();
    protected  AccessSorter sorter = new AccessSorter();

    // 分页功能
    protected Integer pageSize = Integer.MAX_VALUE;// 每页显示的条目数量。
    protected Integer pageIndex = 1; // 页序号
    protected Integer totalCount = 0;// 总条目数
    protected Integer pageCount = 0;// 总页数

    public AccessFilter getFilter() {
        return filter;
    }

    public AccessSorter getSorter() {
        return sorter;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public Integer getPageCount() {
        return ((this.totalCount - 1) / this.pageSize) + 1;
    }

    public void setFilter(AccessFilter filter) {
        this.filter = filter;
    }

    public void setSorter(AccessSorter sorter) {
        this.sorter = sorter;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }



    public AccessParameter() {
    }

    /**
     * 刷新查询参数
     */
    public void refresh(){
        filter.cleanFilter();
        sorter.clearSorter();
        pageSize = Integer.MAX_VALUE;
        pageIndex = 1;
        totalCount = 0;
        pageCount = 0;
    }

    @Override
    public String toString() {
        return "AccessParameter{" +
            "filter=" + filter +
            ", sorter=" + sorter +
            ", pageSize=" + pageSize +
            ", pageIndex=" + pageIndex +
            ", totalCount=" + totalCount +
            ", pageCount=" + getPageCount() +
            '}';
    }
}
